var mongoose = require('mongoose')

mongoose.Promise = global.Promise;

var db = mongoose.createConnection('localhost', 'example1_test6')

db.on('error', console.error.bind(console, '连接错误'))
db.once('open', function(){
    var PersonSchema = new mongoose.Schema({
        name: String,
        type: String
    })
    PersonSchema.statics.findByName = function (name, cb) {
        return this.find({name: new RegExp(name, 'i')}, cb)
    }


    var PersonModel = db.model('Person', PersonSchema)


    var personEntity = new PersonModel({
        name: '2',
        type: 'a1'
    })
personEntity.save()
        .then(function(){
            PersonModel.findByName('2', function(err, persons){
                console.log(persons)
            })
        })




})